﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ATW.MT.BUS;
using System.Data;
using System.Configuration;

namespace ATW.MT.SellManage
{
    public partial class ContractDetail : System.Web.UI.Page
    {
        bus_T_Contract TC = new bus_T_Contract();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (!string.IsNullOrEmpty(Request.QueryString["handler"]))
                {
                    string handler = Request.QueryString["handler"];
                    if (handler == "getContent")
                    {
                        WriteRes(getContent());
                    }
                    if (handler == "getUrl")
                    {
                        WriteRes(getUrl());
                    }
                    return;
                }
                BindData();
            }
        }
        private void BindData()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["cid"]))
            {
                hdfCid.Value = Request.QueryString["cid"];
            }
        }
        private string getContent()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["cid"]))
            {
                string contractID = Request.QueryString["cid"];
                if (!CommonClass.common.filterChar(contractID))
                {
                    return "";
                }
                DataTable dt = TC.ContractSingleQuery(contractID);
                if (dt != null && dt.Rows.Count > 0)
                {
                    return dt.Rows[0]["content"].ToString();
                }
            }
            return "";
        }
        private string getUrl()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["cid"]))
            {
                string contractID = Request.QueryString["cid"];
                if (!CommonClass.common.filterChar(contractID))
                {
                    return "";
                }
                DataTable dt = TC.ContractSingleQuery(contractID);
                string path = ConfigurationManager.AppSettings["pdfAccessPath"];
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["PdfFilePath"].ToString() != "")
                    {
                        return path + dt.Rows[0]["PdfFilePath"].ToString();
                    }
                }
            }
            return "";
        }
        private void WriteRes(string s)
        {
            Response.Clear();
            Response.Write(s);
            Response.End();
        }
    }
}